package com.liunian.algorithmstudy.tree;

public class HasPathSum112 extends TreeNode {

	public boolean hasPathSum(TreeNode root, int targetSum) {
		if (root == null) {
			return false;
		}
		if (root.left == null && root.right == null) {
			return targetSum - root.val == 0;
		}
		boolean l = false;
		if (root.left != null) {
			targetSum -= root.val;
			l = hasPathSum(root.left, targetSum);
			targetSum += root.val;
		}
		boolean r = false;
		if (root.right != null) {
			targetSum -= root.val;
			r = hasPathSum(root.right, targetSum);
			targetSum += root.val;
		}
		return l || r;
	}

}
